<template>
    <sub-box>
        <breadcrumb :title="'申请详情'"></breadcrumb>
        <div v-loading="loading">
            <div class="box white-block" v-if="detail&&detail.flowList[0]">
                <el-timeline>
                    <el-timeline-item :type="list.type==1?'primary':(list.type==2?'success':'danger')"
                                      v-for="(list,index) in detail.flowList" :key="index">
                        <div class="timeline-card">
                            <el-card class="mr20">
                                <p class="time" v-if="list.type==1">待审核</p>
                                <p class="time" v-else-if="list.type==2">审核通过</p>
                                <p class="time" v-else-if="list.type==3">审核不通过</p>
                                <p class="name clearfix">
                                    <span>{{list.createTime}}</span>
                                    {{list.opUserDept}}
                                    <i v-if="list.opUserName">{{list.opUserName}}</i>
                                </p>
                                <p class="remark" :class="{error:list.type==3}" v-if="list.opinion">
                                    审核说明：{{list.opinion}}
                                </p>
                            </el-card>
                        </div>
                    </el-timeline-item>
                </el-timeline>
            </div>
            <div class="box-th white-block mt20" v-if="detail">
                <div class="form-common clearfix">
                    <div class="form-item">
                        <div class="form-item-label">自建系统名称</div>
                        <div class="form-item-content">{{detail.appName}}</div>
                    </div>
                    <div class="form-item">
                        <div class="form-item-label">自建系统代码</div>
                        <div class="form-item-content">{{detail.appCode}}</div>
                    </div>
                    <div class="form-item">
                        <div class="form-item-label">自建系统描述</div>
                        <div class="form-item-content">{{detail.description}}</div>
                    </div>
                </div>
            </div>
            <div class="box-th white-block mt20" v-if="detail">
                <table-example :data="detail.ipList" :tableColumn="header" :slotColumns="slotColumns" class="mt20">
                    <template slot="server" slot-scope="scope">
                        <p v-for="(item,value) in scope.row.resName" :key="value">{{item}}</p>
                    </template>
                </table-example>
            </div>
            <div class="white-block mt20" v-if="detail&&detail.flowResult==1">
                <audit @save="auditSave" :labelWidth="'.9rem'"></audit>
            </div>
        </div>
    </sub-box>
</template>

<script>
    import subBox from '../../components/layout/layout-sub'
    import breadcrumb from '../../components/breadcrumb'
    import tableExample from '../../components/table'
    import audit from '../../components/audit'

    export default {
        data() {
            return {
                tableData: [],
                header: [
                    {
                        prop: 'ip',
                        label: 'IP地址',
                        minWidth: '50%',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'server',
                        label: '绑定服务',
                        minWidth: '50%',
                        align: 'center',
                        headerAlign: 'center'
                    }

                ],
                id: '',
                slotColumns: ['server'],
                loading: false,
                detail: null
            }
        },
        mounted() {
            if (this.$route.query.id) this.id = this.$route.query.id
            this.getDetail()
        },
        methods: {
            getDetail() {
                this.loading = true
                this.$http.get('/dept/workbench/getIpApplyInfo', {
                    id: this.id
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.detail = result.data
                    }
                    this.$method.updateView(false, true)
                }).catch(() => {
                    this.loading = false
                })
            },
            auditSave(form, list, callback) {
                this.loading = true
                this.$http.post('/admin/workbench/ipApprove', {
                    ipApplyNo: this.detail.applyNo,
                    remark: form.remark,
                    result: form.state
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.$emit('upload')
                        if (callback) callback()
                        this.$nextTick(() => {
                            this.$method.historyBack()
                        })

                    }
                }).catch(() => {
                    this.loading = false
                })
            }
        },
        components: {
            subBox,
            breadcrumb,
            tableExample,
            audit
        }
    }
</script>
<style scoped lang="less">
    .box {
        padding-left: 2.5rem;
        .timeline-card {
            display: inline-flex;
            align-items: center;
            > * {
                flex: auto;
            }
            .el-card {
                width: 8rem;
            }
            .timeline-btn {
                button {
                    border-radius: .2rem;
                }
            }
        }
        .time {
            font-size: .2rem;
            margin-bottom: .03rem;
        }
        .name {
            span {
                float: right;
            }
        }
        .remark {
            color: #999;
            &.error {
                color: #E00000;
            }
        }
    }

    .audit {
        max-width: 8rem;
    }
</style>
